layui.use(['laydate', 'laypage', 'layer', 'table', 'upload', 'element'], function(){
	  var laydate = layui.laydate //日期
	  ,laypage = layui.laypage //分页
	  layer = layui.layer //弹层
	  ,table = layui.table //表格
	  ,upload = layui.upload //上传
	  ,element = layui.element; //元素操作
	 
	
	  var $ = layui.$;
	  
	  //监听Tab切换
	  element.on('tab(demo)', function(data){
	    layer.msg('切换了：'+ this.innerHTML);
	    console.log(data);
	  });
	  
	  //执行一个 table 实例
	  table.render({
	     elem: '#seller'
	    ,width:1064
	    ,height: 406
	    ,url: '../../user/findByUsersTypeAll.action?usersType='+getParameter("usersType") //数据接口
	    ,page: true //开启分页
	    ,method:'post'
	    ,size: 'sm'
	    ,cols: [[ //表头
	       {type:'checkbox', fixed: 'left'}
	      ,{field: 'usersName', title: '用户名', align: 'center', width:180, fixed: 'left'}
	      ,{field: 'usersPassword', title: '用户密码', align: 'center', width:120}
	      ,{field: 'businessName', title: '商家/卖家名称', align: 'center', width:120}
	      ,{field: 'usersImage', title: '用户头像', align: 'center', width:160,templet:'#usersImage'}
	      ,{field: 'fullName', title: '用户姓名', align: 'center', width:160}
	      ,{field: 'usersSfz', title: '用户身份证', align: 'center', width:160}
	      ,{field: 'usersPhone', title: '用户电话号码', align: 'center', width: 120}
	      ,{field: 'usersSex', title: '用户性别', align: 'center', width:120}
	      ,{field: 'usersType', title: '用户类型', align: 'center', width:120, templet: '#usersTypes'}
	      ,{fixed: 'right',title: '操作', width: 165, align:'center', toolbar: '#barDemo'}
	    ]]
	  	,id: 'testReload'
	  });
	  
	  //增加
	  $("#add").click(function(){
		  layer.open({
			  title: '用户添加'
			  ,type: 2
			  ,area: ['60%','90%']
			  ,content: 'userAddOrUpdate.html?usersType=2&action=add'
			});
	  });
	  
	  //监听工具条
	  table.on('tool(demo)', function(obj){ //注：tool是工具条事件名，test是table原始容器的属性 lay-filter="对应的值"
	    var data = obj.data //获得当前行数据
	    ,layEvent = obj.event; //获得 lay-event 对应的值
	    if(layEvent === 'del'){
	    	var usersId = data.usersId;
	    	layer.confirm('确认删除该条用户信息吗?', function(index){
	    		  //do something
	    		  var data = {"usersId":usersId};
	    		  var url = "../../user/deletes.action";
	    		  $.ajax({
	    			  url:url,
	    			  data:data,
	    			  success:function(msg){
	    				  if(msg.state == "1"){
	    					  obj.del(); //删除对应行（tr）的DOM结构
	    					  $(".layui-laypage-btn").click()
	    					  layer.msg(msg.msg,{icon:1,time:1000})
	    				  }else {
	    					  layer.msg(msg.msg,{icon:2,time:1000})
	    				  }
	    			  }
	    		  });
	    		  layer.close(index);
	    	});
	    }else if(layEvent === 'edit'){
	    	layer.open({
				  title: '用户修改'
				  ,type: 2
				  ,area: ['60%','90%']
				  ,content: 'userAddOrUpdate.html?usersType=2&action=update&usersId='+data.usersId
				});
	    }
	  });
	
	//根据条件查询
	  $('#search').on('click', function(){
		 var usersName = $("#usersName").val();
		 var businessName = $("#businessName").val();
		 //执行重载
	     table.reload('testReload', {
	       page: {
	         curr: 1 //重新从第 1 页开始
	       }
	       ,where: {
	    	   usersName: usersName,
	    	   businessName: businessName,
	       }
	     });
	  });
	});